/*
 *  PKL 51 GUNUNG KIDUL
 *  Subseksie DATA ENTRY + CAPI
 */

/*
 * PanelKuesioner.java
 *
 * Created on Feb 11, 2012, 10:34:06 PM
 */
package pkl51.view;

import java.awt.CardLayout;
import java.util.logging.Level;
import java.util.logging.Logger;
import pkl51.controller.ActionController;
import pkl51.controller.CardKues;
import pkl51.controller.CardLayoutController;
import pkl51.controller.NewController;
import pkl51.error.EntityException;
import pkl51.util.Message;
import pkl51.view.kuesioner.*;

/**
 *
 * @author Hindarwan
 */
public class PanelKuesioner extends javax.swing.JPanel {

    /**
     * Creates new form PanelKuesioner
     */
    private CardLayoutController cardKuesionerController;
    private NewController newController;

    public CardLayoutController getCardKuesionerController() {
        return cardKuesionerController;
    }

    public PanelKuesioner() {
        initComponents();
        cardKuesionerController = new CardLayoutController();
        cardKuesionerController.setCardLayout((CardLayout) panelKues.getLayout());
        cardKuesionerController.setParentCard(panelKues);
        CardKues.setCard(cardKuesionerController);
        newController = new NewController();
    }

    public void nextPage() {
        CardKues.getCard().next();
    }

    public void previousPage() {
        CardKues.getCard().previous();
    }

    public boolean insertDataKuesioner() {
        try {
            panelBlok123.getController().insertBlok123(panelBlok123);
            panelBlok4.getController().insertAllBlok4();
            panelBlok5.getController().insertBlok5(panelBlok5);
            panelBlok6A.getController().insertBlok6A(panelBlok6A);
            panelBlok6B1.getController().insertAllBlok6B();
            panelBlok6C.getController().insertBlok6C(panelBlok6C);
            Message.infoMessage("Data berhasil disimpan");
            return true;
        } catch (EntityException ex) {
            Logger.getLogger(PanelKuesioner.class.getName()).log(Level.SEVERE, null, ex);
            Message.errorMessage("Data gagal disimpan");
            return false;
        }
    }

    public boolean loadDataKuesioner() {
        try {
            
            panelBlok123.getController().getBlok123ByNKS(panelBlok123);
            
            panelBlok4.getValidasiBlok4().unRegisterValidator();
            panelBlok4.getController().getAllBlok4();
            panelBlok4.getValidasiBlok4().registerValidator();            
            
            panelBlok5.getController().getBlok5ByNKS(panelBlok5);            
            
            panelBlok6A.getController().getBlok6A(panelBlok6A);
            
            panelBlok6B1.getController().getAllBlok6B();
            panelBlok6C.getController().getBlok6CyNKS(panelBlok6C);
            return true;
        } catch (EntityException ex) {
            Logger.getLogger(PanelKuesioner.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
    }

    public boolean updateDataKuesioner() {
        try {
            panelBlok123.getController().updateBlok123(panelBlok123);
            
            panelBlok4.getValidasiBlok4().unRegisterValidator();
            panelBlok4.getController().updateAllBlok4();
            panelBlok5.getController().updateBlok5(panelBlok5);
            panelBlok6A.getController().updateBlok6A(panelBlok6A);
            panelBlok6B1.getController().updateAllBlok6B();
            panelBlok6C.getController().updateBlok6C(panelBlok6C);
            
            Message.infoMessage("Data berhasil diupdate");
            return true;
        } catch (EntityException ex) {
            Logger.getLogger(PanelKuesioner.class.getName()).log(Level.SEVERE, null, ex);
            Message.errorMessage("Data gagal disimpan");
            return false;
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        toolBarKuesioner = new javax.swing.JToolBar();
        buttonNew = new javax.swing.JButton();
        buttonPrevious = new javax.swing.JButton();
        buttonNext = new javax.swing.JButton();
        buttonSave = new javax.swing.JButton();
        panelKues = new javax.swing.JPanel();
        formScroller1 = new pkl51.component.FormScroller();
        panelTransparan1 = new pkl51.component.PanelTransparan();
        panelBlok123 = new pkl51.view.kuesioner.PanelBlok123();
        formScroller2 = new pkl51.component.FormScroller();
        panelTransparan2 = new pkl51.component.PanelTransparan();
        panelBlok4 = new pkl51.view.kuesioner.PanelBlok4();
        formScroller3 = new pkl51.component.FormScroller();
        panelTransparan3 = new pkl51.component.PanelTransparan();
        panelBlok5 = new pkl51.view.kuesioner.PanelBlok5();
        formScroller4 = new pkl51.component.FormScroller();
        panelTransparan4 = new pkl51.component.PanelTransparan();
        panelBlok6A = new pkl51.view.kuesioner.PanelBlok6A();
        formScroller5 = new pkl51.component.FormScroller();
        panelTransparan5 = new pkl51.component.PanelTransparan();
        panelBlok6B1 = new pkl51.view.kuesioner.PanelBlok6B1();
        formScroller6 = new pkl51.component.FormScroller();
        panelTransparan6 = new pkl51.component.PanelTransparan();
        panelBlok6B2 = new pkl51.view.kuesioner.PanelBlok6B2();
        formScroller7 = new pkl51.component.FormScroller();
        panelTransparan7 = new pkl51.component.PanelTransparan();
        panelBlok6B3 = new pkl51.view.kuesioner.PanelBlok6B3();
        formScroller8 = new pkl51.component.FormScroller();
        panelTransparan8 = new pkl51.component.PanelTransparan();
        panelBlok6B4 = new pkl51.view.kuesioner.PanelBlok6B4();
        formScroller9 = new pkl51.component.FormScroller();
        panelTransparan9 = new pkl51.component.PanelTransparan();
        panelBlok6B5 = new pkl51.view.kuesioner.PanelBlok6B5();
        formScroller10 = new pkl51.component.FormScroller();
        panelTransparan10 = new pkl51.component.PanelTransparan();
        panelBlok6B6 = new pkl51.view.kuesioner.PanelBlok6B6();
        formScroller11 = new pkl51.component.FormScroller();
        panelTransparan11 = new pkl51.component.PanelTransparan();
        panelBlok6B7 = new pkl51.view.kuesioner.PanelBlok6B7();
        formScroller12 = new pkl51.component.FormScroller();
        panelTransparan12 = new pkl51.component.PanelTransparan();
        panelBlok6B8 = new pkl51.view.kuesioner.PanelBlok6B8();
        formScroller13 = new pkl51.component.FormScroller();
        panelTransparan13 = new pkl51.component.PanelTransparan();
        panelBlok6C = new pkl51.view.kuesioner.PanelBlok6C();

        setPreferredSize(new java.awt.Dimension(920, 900));

        toolBarKuesioner.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        toolBarKuesioner.setFloatable(false);
        toolBarKuesioner.setRollover(true);

        buttonNew.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pkl51/image/new.png"))); // NOI18N
        buttonNew.setFocusable(false);
        buttonNew.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonNew.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonNew.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonNewActionPerformed(evt);
            }
        });
        toolBarKuesioner.add(buttonNew);

        buttonPrevious.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pkl51/image/left-icon.png"))); // NOI18N
        buttonPrevious.setFocusable(false);
        buttonPrevious.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonPrevious.setOpaque(false);
        buttonPrevious.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonPrevious.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonPreviousActionPerformed(evt);
            }
        });
        toolBarKuesioner.add(buttonPrevious);

        buttonNext.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pkl51/image/right-icon.png"))); // NOI18N
        buttonNext.setFocusable(false);
        buttonNext.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonNext.setOpaque(false);
        buttonNext.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonNext.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonNextActionPerformed(evt);
            }
        });
        toolBarKuesioner.add(buttonNext);

        buttonSave.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pkl51/image/save.png"))); // NOI18N
        buttonSave.setFocusable(false);
        buttonSave.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonSave.setOpaque(false);
        buttonSave.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonSaveActionPerformed(evt);
            }
        });
        toolBarKuesioner.add(buttonSave);

        panelKues.setAutoscrolls(true);
        panelKues.setLayout(new java.awt.CardLayout());

        formScroller1.setOpaque(false);
        formScroller1.setPreferredSize(new java.awt.Dimension(789, 474));

        panelTransparan1.setBorder(null);
        panelTransparan1.setPreferredSize(new java.awt.Dimension(769, 918));
        panelTransparan1.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.CENTER, 20, 20));
        panelTransparan1.add(panelBlok123);

        formScroller1.setViewportView(panelTransparan1);

        panelKues.add(formScroller1, "cardForm1");

        formScroller2.setOpaque(false);
        formScroller2.setPreferredSize(new java.awt.Dimension(789, 474));

        panelTransparan2.setBorder(null);
        panelTransparan2.setPreferredSize(new java.awt.Dimension(930, 1122));
        panelTransparan2.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.CENTER, 20, 20));
        panelTransparan2.add(panelBlok4);

        formScroller2.setViewportView(panelTransparan2);

        panelKues.add(formScroller2, "cardForm2");

        formScroller3.setOpaque(false);
        formScroller3.setPreferredSize(new java.awt.Dimension(789, 474));

        panelTransparan3.setBorder(null);
        panelTransparan3.setMinimumSize(new java.awt.Dimension(0, 0));
        panelTransparan3.setPreferredSize(new java.awt.Dimension(721, 1611));
        panelTransparan3.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.CENTER, 20, 20));
        panelTransparan3.add(panelBlok5);

        formScroller3.setViewportView(panelTransparan3);

        panelKues.add(formScroller3, "cardForm3");

        formScroller4.setOpaque(false);
        formScroller4.setPreferredSize(new java.awt.Dimension(789, 474));

        panelTransparan4.setBorder(null);
        panelTransparan4.setPreferredSize(new java.awt.Dimension(765, 1086));
        panelTransparan4.add(panelBlok6A);

        formScroller4.setViewportView(panelTransparan4);

        panelKues.add(formScroller4, "cardForm4");

        formScroller5.setOpaque(false);
        formScroller5.setPreferredSize(new java.awt.Dimension(789, 474));

        panelTransparan5.setBorder(null);
        panelTransparan5.setPreferredSize(new java.awt.Dimension(820, 1132));
        panelTransparan5.add(panelBlok6B1);

        formScroller5.setViewportView(panelTransparan5);

        panelKues.add(formScroller5, "cardForm5");

        formScroller6.setOpaque(false);
        formScroller6.setPreferredSize(new java.awt.Dimension(789, 474));

        panelTransparan6.setBorder(null);
        panelTransparan6.setPreferredSize(new java.awt.Dimension(820, 1399));
        panelTransparan6.add(panelBlok6B2);

        formScroller6.setViewportView(panelTransparan6);

        panelKues.add(formScroller6, "cardForm6");

        formScroller7.setOpaque(false);
        formScroller7.setPreferredSize(new java.awt.Dimension(820, 1210));

        panelTransparan7.setBorder(null);
        panelTransparan7.setPreferredSize(new java.awt.Dimension(765, 1399));
        panelTransparan7.add(panelBlok6B3);

        formScroller7.setViewportView(panelTransparan7);

        panelKues.add(formScroller7, "cardForm7");

        formScroller8.setOpaque(false);
        formScroller8.setPreferredSize(new java.awt.Dimension(789, 474));

        panelTransparan8.setBorder(null);
        panelTransparan8.setPreferredSize(new java.awt.Dimension(820, 1269));
        panelTransparan8.add(panelBlok6B4);

        formScroller8.setViewportView(panelTransparan8);

        panelKues.add(formScroller8, "cardForm8");

        formScroller9.setOpaque(false);
        formScroller9.setPreferredSize(new java.awt.Dimension(789, 474));

        panelTransparan9.setBorder(null);
        panelTransparan9.setPreferredSize(new java.awt.Dimension(820, 1217));
        panelTransparan9.add(panelBlok6B5);

        formScroller9.setViewportView(panelTransparan9);

        panelKues.add(formScroller9, "cardForm9");

        formScroller10.setOpaque(false);
        formScroller10.setPreferredSize(new java.awt.Dimension(789, 474));

        panelTransparan10.setBorder(null);
        panelTransparan10.setPreferredSize(new java.awt.Dimension(820, 1254));
        panelTransparan10.add(panelBlok6B6);

        formScroller10.setViewportView(panelTransparan10);

        panelKues.add(formScroller10, "cardForm10");

        formScroller11.setOpaque(false);
        formScroller11.setPreferredSize(new java.awt.Dimension(789, 474));

        panelTransparan11.setBorder(null);
        panelTransparan11.setPreferredSize(new java.awt.Dimension(820, 1352));
        panelTransparan11.add(panelBlok6B7);

        formScroller11.setViewportView(panelTransparan11);

        panelKues.add(formScroller11, "cardForm11");

        formScroller12.setOpaque(false);
        formScroller12.setPreferredSize(new java.awt.Dimension(789, 474));

        panelTransparan12.setBorder(null);
        panelTransparan12.setPreferredSize(new java.awt.Dimension(765, 1500));
        panelTransparan12.add(panelBlok6B8);

        formScroller12.setViewportView(panelTransparan12);

        panelKues.add(formScroller12, "cardForm12");

        formScroller13.setOpaque(false);
        formScroller13.setPreferredSize(new java.awt.Dimension(789, 474));

        panelTransparan13.setBorder(null);
        panelTransparan13.setPreferredSize(new java.awt.Dimension(765, 1132));
        panelTransparan13.add(panelBlok6C);

        formScroller13.setViewportView(panelTransparan13);

        panelKues.add(formScroller13, "cardForm13");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(panelKues, javax.swing.GroupLayout.DEFAULT_SIZE, 920, Short.MAX_VALUE)
            .addComponent(toolBarKuesioner, javax.swing.GroupLayout.DEFAULT_SIZE, 920, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(toolBarKuesioner, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(panelKues, javax.swing.GroupLayout.DEFAULT_SIZE, 851, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

private void buttonNextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonNextActionPerformed
// TODO add your handling code here:
    nextPage();
}//GEN-LAST:event_buttonNextActionPerformed

private void buttonPreviousActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonPreviousActionPerformed
// TODO add your handling code here:
    previousPage();
}//GEN-LAST:event_buttonPreviousActionPerformed

private void buttonSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSaveActionPerformed
    
    if(ActionController.isEntry()){
        insertDataKuesioner();
    } else{
        updateDataKuesioner();
    }
    
}//GEN-LAST:event_buttonSaveActionPerformed

    private void buttonNewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonNewActionPerformed
        newController.resetAllModel();
        panelBlok123.refreshView();
        panelBlok4.refreshView();
        panelBlok5.refreshView();
        panelBlok6A.refreshView();
        panelBlok6B1.refreshView();
        panelBlok6B2.refreshView();
        panelBlok6B3.refreshView();
        panelBlok6B4.refreshView();
        panelBlok6B5.refreshView();
        panelBlok6B6.refreshView();
        panelBlok6B7.refreshView();
        panelBlok6B8.refreshView();
        panelBlok6C.refreshView();
    }//GEN-LAST:event_buttonNewActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton buttonNew;
    private javax.swing.JButton buttonNext;
    private javax.swing.JButton buttonPrevious;
    private javax.swing.JButton buttonSave;
    private pkl51.component.FormScroller formScroller1;
    private pkl51.component.FormScroller formScroller10;
    private pkl51.component.FormScroller formScroller11;
    private pkl51.component.FormScroller formScroller12;
    private pkl51.component.FormScroller formScroller13;
    private pkl51.component.FormScroller formScroller2;
    private pkl51.component.FormScroller formScroller3;
    private pkl51.component.FormScroller formScroller4;
    private pkl51.component.FormScroller formScroller5;
    private pkl51.component.FormScroller formScroller6;
    private pkl51.component.FormScroller formScroller7;
    private pkl51.component.FormScroller formScroller8;
    private pkl51.component.FormScroller formScroller9;
    private pkl51.view.kuesioner.PanelBlok123 panelBlok123;
    private pkl51.view.kuesioner.PanelBlok4 panelBlok4;
    private pkl51.view.kuesioner.PanelBlok5 panelBlok5;
    private pkl51.view.kuesioner.PanelBlok6A panelBlok6A;
    private pkl51.view.kuesioner.PanelBlok6B1 panelBlok6B1;
    private pkl51.view.kuesioner.PanelBlok6B2 panelBlok6B2;
    private pkl51.view.kuesioner.PanelBlok6B3 panelBlok6B3;
    private pkl51.view.kuesioner.PanelBlok6B4 panelBlok6B4;
    private pkl51.view.kuesioner.PanelBlok6B5 panelBlok6B5;
    private pkl51.view.kuesioner.PanelBlok6B6 panelBlok6B6;
    private pkl51.view.kuesioner.PanelBlok6B7 panelBlok6B7;
    private pkl51.view.kuesioner.PanelBlok6B8 panelBlok6B8;
    private pkl51.view.kuesioner.PanelBlok6C panelBlok6C;
    private javax.swing.JPanel panelKues;
    private pkl51.component.PanelTransparan panelTransparan1;
    private pkl51.component.PanelTransparan panelTransparan10;
    private pkl51.component.PanelTransparan panelTransparan11;
    private pkl51.component.PanelTransparan panelTransparan12;
    private pkl51.component.PanelTransparan panelTransparan13;
    private pkl51.component.PanelTransparan panelTransparan2;
    private pkl51.component.PanelTransparan panelTransparan3;
    private pkl51.component.PanelTransparan panelTransparan4;
    private pkl51.component.PanelTransparan panelTransparan5;
    private pkl51.component.PanelTransparan panelTransparan6;
    private pkl51.component.PanelTransparan panelTransparan7;
    private pkl51.component.PanelTransparan panelTransparan8;
    private pkl51.component.PanelTransparan panelTransparan9;
    private javax.swing.JToolBar toolBarKuesioner;
    // End of variables declaration//GEN-END:variables

    public PanelBlok123 getPanelBlok123() {
        return panelBlok123;
    }

    public PanelBlok4 getPanelBlok4() {
        return panelBlok4;
    }

    public PanelBlok5 getPanelBlok5() {
        return panelBlok5;
    }

    public PanelBlok6A getPanelBlok6A() {
        return panelBlok6A;
    }

    public PanelBlok6B1 getPanelBlok6B1() {
        return panelBlok6B1;
    }

    public PanelBlok6B2 getPanelBlok6B2() {
        return panelBlok6B2;
    }

    public PanelBlok6B3 getPanelBlok6B3() {
        return panelBlok6B3;
    }

    public PanelBlok6B4 getPanelBlok6B4() {
        return panelBlok6B4;
    }

    public PanelBlok6B5 getPanelBlok6B5() {
        return panelBlok6B5;
    }

    public PanelBlok6B6 getPanelBlok6B6() {
        return panelBlok6B6;
    }

    public PanelBlok6B7 getPanelBlok6B7() {
        return panelBlok6B7;
    }

    public PanelBlok6B8 getPanelBlok6B8() {
        return panelBlok6B8;
    }

    public PanelBlok6C getPanelBlok6C() {
        return panelBlok6C;
    }

}
